<?php
/**
 * Created by JetBrains PhpStorm.
 * User: yy
 * Date: 13-7-22
 * Time: 下午4:25
 * To change this template use File | Settings | File Templates.
 */
class AE_Model_Content extends Extension_Model_AppEngineBase{
    protected function _signalToModel($single){
        return $single;
    }

    public function isexist($rid){
        return $this->activeDb()->tables('appengine_advice_contents')->select('count(*)')->where('advice_id = ?',array($rid))->fetchOne();
    }
    //创建
    public function create($insertArray){
        if(false !== $this->activeDb()->insert($insertArray,"appengine_advice_contents")){
            $this->activeDb()->lastInsertId() ;
        }else{
            return false;
        }
    }
    public function delete($advice_id){
        return $this->activeDb()->where("advice_id = ?",$advice_id)->delete("appengine_advice_contents");
    }
    public function getByAppId($appId,$limit = null,$sort=null){
        $limit = $this->parseLimit($limit,0,10);
        $sort = $this->parseSort($sort,"createtime","DESC");
        $list = $this->activeDb()->tables("appengine_advice_contents")->where('app_id=?',array($appId))->limit($limit[0],$limit[1])->sort($sort[0],$sort[1])->fetchAll();
        $total = $this->activeDb()->tables("appengine_advice_contents")->where('app_id=?',array($appId))->select("COUNT(*) as total")->fetchOne();
        return $this->listFormat($total,$this->_toModel($list));
    }
    public function getById($appId){
        return $this->activeDb()->tables("appengine_advice_contents")->where("advice_id = ?",$appId)->fetchRow();
    }


    public function removeByID($appId){
        return $this->activeDb()->where("app_id = ?",$appId)->delete("appengine_advice_contents");
    }

}